package xyz.ljcc.ccmt.handler;

import java.net.URL;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class PageJumpHandler {
	
	Logger logger = LoggerFactory.getLogger(PageJumpHandler.class);
	
	@GetMapping("/toPage")
	public String toPage(String url) {
		if(StringUtils.isEmpty(url)) {
			return "pages/404";
		}else {
			URL fileUrl = this.getClass().getClassLoader().getResource("templates/"+url + ".html");
			if(fileUrl != null) {
				return url;
			}else {
				logger.error("菜单连接地址：" + url + " 不存在，请检查！");
				return "pages/404";
			}
		}
	}
	
	@GetMapping("/login.html")
	public String login() {
		return "login";
	}
	
}
